#encoding: utf-8
class AddColumnSlugToGroupsThreads < ActiveRecord::Migration
  def self.up
    add_column :groups_threads, :slug, :string
    
    GroupsThread.all.each do |thread|
    	slug = thread.title.downcase
    	slug.gsub!('š','s')
	  	slug.gsub!('đ','d')
	  	slug.gsub!('č','c')
	  	slug.gsub!('ć','c')
	  	slug.gsub!('ž','z')
    	slug.gsub!(/[^a-z0-9\s]/, '') 
    	slug.gsub!(/\s+/,'-')
    	thread.slug = slug
    	thread.save
    end
  end

  def self.down
    remove_column :groups_threads, :slug
  end
end
